#include "Container.h"

void Container::add(Widget *widget){
	widgets.push_back(widget);
}

void Container::erase(Widget *widget){
	widgets.remove(widget);
}

Container::Container(int posX, int posY,SDL_Surface* surface, Widget *parent)
:Widget(posX, posY,surface, parent){}


void Container::showOn(SDL_Surface* surface) {
	std::list<Widget*>::iterator it_widget;
	for (it_widget = widgets.begin(); it_widget != widgets.end(); ++it_widget) {
		(*it_widget)->showOn(surface);
	}
}

void Container::handleEvent(Event event) {
	std::list<Widget*>::iterator it_widget;
	for (it_widget = widgets.begin(); it_widget != widgets.end(); ++it_widget) {
		(*it_widget)->handleEvent(event);
	}
}

void Container::resolve() {
	std::list<Widget*>::iterator it_widget;
	for (it_widget = widgets.begin(); it_widget != widgets.end(); ++it_widget) {
		(*it_widget)->resolve();
	}
}


Container::~Container() {
	while(!widgets.empty()){
		delete widgets.back();
		widgets.pop_back();
	}
}

